home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_04 / saks / xr.cpp < prev    next >
C/C++ Source or Header  |  1994-02-09  |  1KB  |  57 lines

  1.  
  2. ----------
  3.  
  4. Listing 1 - the main module for the cross-reference program
  5.  
  6. //
  7. // xr.cpp - a cross-reference generator
  8. //
  9. #include <assert.h>
  10. #include <ctype.h>
  11. #include <stdio.h>
  12.  
  13. #include "xrt.h"
  14.  
  15. int getword(char *word, size_t lim)
  16.     {
  17.     int c;
  18.     char *w = word;
  19.  
  20.     assert(lim > 2);
  21.     while (isspace(c = fgetc(stdin)) && c != '\n')
  22.         ;
  23.     if (c != EOF)
  24.         *w++ = c;
  25.     if (!isalpha(c))
  26.         {
  27.         *w = '\0';
  28.         return c;
  29.         }
  30.     for ( ; lim-- > 0; ++w)
  31.         if (!isalnum(*w = fgetc(stdin)))
  32.             {
  33.             ungetc(*w, stdin);
  34.             break;
  35.             }
  36.     *w = '\0';
  37.     return *word;
  38.     }
  39.  
  40. #define MAXWORD 100
  41.  
  42. int main()
  43.     {
  44.     char word[MAXWORD];
  45.     unsigned lineno = 1;
  46.     xrt x;
  47.  
  48.     while (getword(word, MAXWORD) != EOF)
  49.         if (isalpha(word[0]))
  50.             x.add(word, lineno);
  51.         else if (word[0] == '\n')
  52.             ++lineno;
  53.     x.print();
  54.     return 0;
  55.     }
  56.  
  57.